﻿using System;
using System.Text;
using System.Web;
using WebDotNet.Extensions;
using WebDotNet.Samples.TodoList.App.Entities;
using WebDotNet.Samples.TodoList.App.Model;

namespace WebDotNet.Samples.TodoList.App.Handlers
{
	public class Delete
	{
		public StringBuilder Post(HttpContextBase httpContextBase)
		{
			Guid id = Guid.Parse(httpContextBase.Request.Form["id"]);

			new XmlRepository<Todo>()
				.RemoveAll(t => t.Id == id)
				.Save();

			if (httpContextBase.IsAjaxRequest())
			{
				return null;
			}
			else
			{
				httpContextBase.Response.Redirect("~/", true);
				return null;
			}
		}
	}
}
